package com.feng.leetcode;

/**
 * @author feng
 * @decrition
 * @date 2022/10/2522:38
 */
public class L915 {
    class Solution {
        public int partitionDisjoint(int[] nums) {
            if (nums.length < 1) {
                return 0;
            }
            int temp = nums[0];
            int result = 1;
            int max = 0;
            boolean flag = true;
            for (int i = 1; i < nums.length; i++) {
                if (flag && temp > nums[i]) {
                    result = i + 1;
                    continue;
                }
                if (max == 0) {
                    max = nums[i];
                    flag = false;
                    continue;
                }
                if (max < nums[i]) {
                    max = nums[i];
                    flag = false;
                }
                if (!flag && temp > nums[i]) {
                    temp = max;
                    result = i + 1;
                    flag = true;
                }
            }
            return result;
        }
    }
}
